<template>
  <div>
    <h4>个人订单详情</h4>
    订单号: {{orderObj.id}}<br><br>
    收货人: {{orderObj.consignee}}<br><br>
    收货地址: {{orderObj.address}}<br><br>
    收货人电话: {{orderObj.phone}}<br><br>
    下单时间: {{orderObj.orderDate}}<br><br>
    订单总价: {{orderObj.totalPrice}}<br><br>
    订单状态: {{orderObj.status}}<br>
    <h4>订单明细</h4>
    <el-table :data="orderObj.detailList" style="width: 100%" border="1">
      <el-table-column prop="productBean.id" label="商品编号"  />
      <el-table-column prop="productBean.name" label="商品名" />
      <el-table-column prop="productBean.price" label="单价" />
      <el-table-column prop="buyNum" label="购买数量" />
    </el-table>
    <el-button type="primary" @click="managerUpdateStatus()">发货</el-button>
    <el-button type="primary" @click=" this.$router.push('/manager')">返回</el-button>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      orderObj:{},
      orderBean:{}
    }
  },methods:{
    findById(){
      let str=sessionStorage.getItem("orderBean");
      //字符串转对象
      this.orderBean = JSON.parse(str);
      let orderId=this.orderBean.id;
      axios.get("/project/order/findById",{params:{orderId}}).then(resp=> {
        this.orderObj = resp.data;
      });
    },managerUpdateStatus(){
      let str=sessionStorage.getItem("orderBean");
      this.orderBean = JSON.parse(str);
      let orderId=this.orderBean.id;
      if(this.orderBean.status=="未发货"){
        axios.get("/project/order/managerUpdateStatus",{params:{orderId}}).then(resp=> {
            if(resp.data=="ok"){
              alert("发货成功");
              this.findById(orderId);
            }
        })
      }else {
        alert("该订单发货中/已完结")
      }
  }
  },created() {
    this.findById();
  }
}
</script>

<style scoped>

</style>